{% extends 'layout/basic.html' %}

{% load static %}

{% block title %}{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
    <style>
        .error-msg {
            color: red;
            position: absolute;
            font-size: 13px;
        }
    </style>
{% endblock %}


{% block content %}
    <div class="container">
        <div class="account">
            <div class="title">用户登录</div>
            <form action="/login/" method="post" novalidate>
                {% csrf_token %}
                {% for field in form %}
                    {% if field.name == 'code' %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                            <div class="clearfix">
                                <div class="col-md-7" style="padding-left: 0px;">
                                    {{ field }}
                                    <span class="error-msg">{{ field.errors.0 }}</span>
                                </div>
                                <div class="col-md-5">
                                    {#<img src="/image/code/" alt="">#}
                                    <img src="/image/code/" alt="" id="imageCode" title="点击更换图片">
                                </div>
                            </div>
                        </div>
                    {% else %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                            {{ field }}
                            <span class="error-msg">{{ field.errors.0 }}</span>
                        </div>
                    {% endif %}
                {% endfor %}

                <div>
                    <div style="float: right;">
                        <a href="/login/sms/">短信登录</a>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-3">
                        <input type="submit" class="btn btn-primary" value="登  录">
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        // 点击图片验证码 更换图片
        $(function () {
            $('#imageCode').click(function () {
                // thi即点击的标签
                var oldSrc = $(this).attr('src');
                // 地址改变，就再发一次请求
                $(this).attr('src', oldSrc + '?');
            });
        });
    </script>
{% endblock %}
